package com.gxh.shiro.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gxh.shiro.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author Xiaohong X Gou
 * @createTime 2023-04-11 16:42
 * @description
 */
@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT NAME FROM role WHERE id in\n" +
            " (SELECT rid from role_user WHERE uid in (\n" +
            "\t\tSELECT id from user where name = #{principal}))")
    List<String> getUserRoleInfo(@Param("principal") String principal);

    @Select({"<script>",
            "select info from permissions WHERE id in (",
            "select pid from role_ps WHERE rid in (",
            "SELECT id from role WHERE name in",
            "<foreach collection='roles' item='name' open='(' separator=',' close=')'>",
            "#{name}",
            "</foreach>",
            "))",
            "</script>"})
    List<String> getUserPermissionsInfoMapper(@Param("roles") List<String> roles);
}
